import 'dart:ui';

import 'package:flutter/material.dart';

class LYTextField extends StatefulWidget {
  const LYTextField({super.key});

  @override
  State<LYTextField> createState() => _LYTextFieldState();
}

class _LYTextFieldState extends State<LYTextField> {
  final FocusNode focusNode = FocusNode();
  bool isVisible = false;
  @override
  Widget build(BuildContext context) {
    FlutterView view = View.of(context);
    final bottom = MediaQueryData.fromView(view).viewInsets.bottom - 50;
    debugPrint('===$bottom');
    return Scaffold(
      appBar: AppBar(
        title: Text('输入框'),
      ),
      resizeToAvoidBottomInset: false,
      body: InkResponse(
        onTap: () {
          isVisible = false;
          focusNode.unfocus();
          setState(() {});
        },
        child: Stack(
          fit: StackFit.expand,
          children: [
            Positioned(
                bottom: bottom,
                left: 0,
                right: 0,
                child: Visibility(
                  visible: isVisible,
                  child: Container(
                    padding: const EdgeInsets.only(left: 20, right: 20),
                    child: TextField(
                      focusNode: focusNode,
                      decoration: const InputDecoration(
                          border: OutlineInputBorder(
                              borderSide:
                                  BorderSide(color: Colors.black, width: 1)),
                          hintText: '请输入'),
                    ),
                  ),
                ))
          ],
        ),
      ),
      floatingActionButton: InkWell(
        onTap: () {
          isVisible = true;

          focusNode.requestFocus();
          setState(() {});
        },
        child: Container(
          height: 50,
          width: 50,
          decoration: BoxDecoration(borderRadius: BorderRadius.circular(25)),
          child: Text('点击'),
        ),
      ),
    );
  }
}
